<?php
class Register extends Module{
	function Register($row){
		Module::Module($row);
		switch(Url::get('cmd')){
			case 'create_image':
				require_once 'forms/create_image.php';
				break;
			case 'check_user':
				$this->check_user();
				exit();
			case 'check_email':
				$this->check_email();
				exit();
			case 'check_security_code':
				$this->check_security_code();
				exit();
			case 'check_email_format':
				$this->check_email_format();
				exit();
			default:
				require_once 'forms/register.php';
				$this->add_form(new RegisterForm);
				break;
		}
	}
	
	function check_user(){
		if(Url::get('user_id') and DB::fetch('select * from user where user_name="'.Url::get('user_id').'"')){
			echo 'F';
			return true;	
		}		
		echo 'T';
		return false;
	}
	
	function check_security_code(){
		if(Url::get('sercurity_code') and Url::get('sercurity_code') != $_SESSION['security_code']){
			echo 'T';
		}
		else{
			echo 'F';
		}
	}
	
	function check_email(){
		$email_type = new EmailType(true,'invalid_email');
		
		$email=Url::get('email');
		
		if($email && eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$email)){
			//echo 'Format-T';
			if(DB::fetch('select id,user_name,email from user where email="'.addslashes($email).'"')){
				echo 'Exist-T';
			}
			else{
				echo 'Exist-F';
			}
		}
		else{
			echo 'Format-F';			
		}
	}
}
?>